package com.coocaa.ops.admin.v1.module.provider.impl;

import com.coocaa.ops.admin.v1.module.biz.impl.ModuleInfoBizImpl;
import com.coocaa.ops.admin.v1.module.convert.ModuleQueryConverter;
import com.coocaa.ops.admin.v1.module.model.ModuleInfoModel;
import com.coocaa.ops.admin.v1.module.model.query.ModuleRlsTabQueryModel;
import com.coocaa.ops.admin.v1.module.provider.IModuleInfoQueryProvider;
import com.coocaa.ops.admin.v1.tab.biz.impl.TabInfoBizImpl;
import com.coocaa.ops.common.core.biz.module.entity.ModuleInfoEntity;

import com.coocaa.ops.common.core.base.model.PageResultModel;
import com.coocaa.ops.common.core.base.util.PageQueryUtil;
import com.coocaa.ops.common.core.biz.module.entity.ModuleTabContentConfigInfo;
import com.coocaa.ops.common.core.biz.tab.entity.TabInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author bjh
 * @description 模块信息原始表-查询provider接口实现
 * @date : 2020-06-15 16:34:46
 */
@Service
public class ModuleInfoQueryProviderImpl implements IModuleInfoQueryProvider {
    @Autowired
    private ModuleInfoBizImpl thisBizImpl;
    @Autowired
    private TabInfoBizImpl tabInfoBiz;


    /**
     * 获取详情信息
     *
     * @param id
     * @param version
     * @return
     */
    @Override
    public ModuleInfoEntity getDetailInfo(Integer id, Integer version) {
        ModuleInfoEntity entity = this.getEntityByIdAndVersion(id, version);
        TabInfoEntity topTab = (TabInfoEntity) tabInfoBiz.queryById(entity.getTopTabId());
        entity.setTopTabInfo(topTab);
        TabInfoEntity bottomTab = (TabInfoEntity) tabInfoBiz.queryById(entity.getBottomTabId());
        entity.setBottomTabInfo(bottomTab);
        ModuleRlsTabQueryModel model = new ModuleRlsTabQueryModel(entity.getId(), entity.getCurrentVersion());
        List<ModuleTabContentConfigInfo> dmpTabList = thisBizImpl.queryDmpTabList(model);
        ModuleQueryConverter.handleSetDmpTab(entity, dmpTabList);
        return entity;
    }

    /**
     * 分页数据-菜单自己使用
     *
     * @param model
     * @return
     */
    @Override
    public PageResultModel<ModuleInfoEntity> pageList(ModuleInfoModel model) {
        Map<String, Object> params = PageQueryUtil.getFilterMap(model);
        PageResultModel<ModuleInfoEntity> pageResult = thisBizImpl.getCommonPageList(params, true);
        return pageResult;
    }

    /**
     * 分页数据-其他处选择
     *
     * @param model
     * @return
     */
    @Override
    public PageResultModel<ModuleInfoEntity> dataList(ModuleInfoModel model) {
        Map<String, Object> params = PageQueryUtil.getFilterMap(model);
        PageResultModel<ModuleInfoEntity> pageResult = thisBizImpl.getCommonPageList(params, false);
        return pageResult;

    }

    /*************** ===私有方法=== ********************* ===start=== ***************************************/

    /**
     * 获取基础信息-根据ID和版本
     *
     * @param id
     * @param version
     * @return
     */
    private ModuleInfoEntity getEntityByIdAndVersion(Integer id, Integer version) {
        return thisBizImpl.getEntityByIdAndVersion(id, version);
    }


}
